// GLOBAL VARIABLES

var obj;
	///MAP Variables
var markers=[];
var stationsIds=[];
var stationId;
var currentLocation ;

var  latLngPos , sibiuCenterLatLng, swSibiuLatLong ,neSibiuLatLong , latLngSibiuBounds;

var markBubble,markerYourPos,marker,selectedMarkerBubble ;
 
var mapPanel;
	//BUSSES variables
var selectedBusses = [];

	//TIME variables
var picker; 
var pickerSelectedValue;
var currentDate;

  //SCHEDUELE variables



var listScheduelePanel;

var schedueleList;

var hoursInterval;






var listBusPanel;
 //GLOBAL  FUNCTIONS
  //creates city bounds
 function initLocationBounds(){
	  latLngPos = new google.maps.LatLng(currentLocation.latitude,currentLocation.longitude);
	  sibiuCenterLatLng = new google.maps.LatLng(45.785000000,24.150000000); 
	  swSibiuLatLong = new google.maps.LatLng(45.740000000,24.07000000);
	  neSibiuLatLong = new google.maps.LatLng(45.830000000,24.20000000); 
	  latLngSibiuBounds = new google.maps.LatLngBounds( swSibiuLatLong, neSibiuLatLong) ;
	  
	  
	  
	  
	  //if position is not in sibiu bounds 
		 if (!latLngSibiuBounds.contains(latLngPos)){
			//move position to Sibiu
			 latLngPos = sibiuCenterLatLng;
		}
};



//populate currentLocation with the current location
 function locatePosition(){
	 var geo = new Ext.util.GeoLocation({
		    autoUpdate:false,
		    listeners: {
		        locationupdate: function (geo) {
		        	currentLocation = geo;
		        
		        },
		        locationerror: function (   geo,
		                                    bTimeout, 
		                                    bPermissionDenied, 
		                                    bLocationUnavailable, 
		                                    message) {
		            if(bTimeout){
		                alert('Timeout occurred.');
		            }
		            else{
		                alert('Error occurred.');
		            }
		        }
		    }
		});
		geo.updateLocation();
		markBubble = new google.maps.InfoWindow(); 
		}
 
 function setTitle(  obj,   title){
	 var titleBar = obj.application.viewport.query('#titleBar')[0];
 	titleBar.setTitle(title);
 }
 
 
 function emptySelectedBusses(){
	 for(var i=0; i<selectedBusses.length ;i++){
	    selectedBusses.pop();
	 }
	 selectedBusses = [];
 }
 //MAIN :
   //REGISTERS App as a name and starts te app 
 
 Ext.setup({
	   statusBarStyle:  'black-translucent', 
	   phoneStartupScreen: 'res/images/icons/phone_startup.png',
	   icon: 'res/images/icons/icon.png',
	   glossOnIcon: true, 
 
 });
 
  Ext.regApplication({
    name: 'App',
    //goes to  first page( by calling function index from  controller Home
    defaultUrl: 'Home/index',
    launch: function()
    {
    	 obj = this;
		//calls global  function to find  out position of device
    		//(should make a check wheter it is online or offlin)
    	locatePosition();
    	//viewport
    	
    	//add the main panel asa  viewport
    	 this.viewport = new App.views.Viewport();
    },
});